package Exercise;

import java.util.Scanner;

public class demo18 {
    /** 多重背包问题
     *
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int [] v = new int[25000];
        int [] w = new int[25000];
        int [] f = new int[25000];
        int count = 0;//用来表示还剩几种物品
        int a,b,s,k = 1;
        //k就相当于每次多少个物品
        for (int i = 1; i <= n ; i++) {
            a = sc.nextInt();//体积
            b = sc.nextInt();//价值
            s = sc.nextInt();//数量
            while(k<=s){
                count++;
                v[count] = a*k;
                w[count] = b*k;
                s -= k;
                k *= 2;
            }

            if(s>0){//如果还有多余空间
                count++;
                v[count] = a*s;
                w[count] = b*s;
            }
        }
        n = count;//

        for (int i = 1; i <= n ; i++) {//这里写一遍0/1背包一维实现便可
            for (int j = m; j >=v[i] ; j--) {
                f[j] = Math.max(f[j],f[j-v[i]]+w[i]);
            }
        }

        System.out.println(f[m]);
    }
}
